package flc.ast.fragment;

import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.Random;

import flc.ast.R;
import flc.ast.activity.SelLevelActivity;
import flc.ast.databinding.FragmentGuessBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.event.EventStatProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link GuessFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class GuessFragment extends BaseNoModelFragment<FragmentGuessBinding> {

    private int kind = 0;

    @Override
    protected int onCreate() {
        return R.layout.fragment_guess;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);
        mDataBinding.rlGame1.setOnClickListener(this);
        mDataBinding.rlGame2.setOnClickListener(this);
        mDataBinding.rlGame3.setOnClickListener(this);
        mDataBinding.tvStartChallenge.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.rlGame1://看图猜剧名
                clearSelection();
                kind = 0;
                mDataBinding.ivGame1Sel.setImageResource(R.drawable.an_xz1);
                mDataBinding.tvGame1.setTextColor(Color.parseColor("#FECD34"));
                break;
            case R.id.rlGame2://看图猜角色
                clearSelection();
                kind = 1;
                mDataBinding.ivGame2Sel.setImageResource(R.drawable.an_xz1);
                mDataBinding.tvGame2.setTextColor(Color.parseColor("#FECD34"));
                break;
            case R.id.rlGame3://看图猜类型
                clearSelection();
                kind = 2;
                mDataBinding.ivGame3Sel.setImageResource(R.drawable.an_xz1);
                mDataBinding.tvGame3.setTextColor(Color.parseColor("#FECD34"));
                break;
            case R.id.tvStartChallenge://开始挑战
                SelLevelActivity.kind = kind;
                startActivity(SelLevelActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        Random random = new Random();
        int num = random.nextInt(500);
        mDataBinding.tvChallengeNum.setText(getString(R.string.challenge_num, num));
    }

    private void clearSelection() {
        mDataBinding.ivGame1Sel.setImageResource(R.drawable.an_xz2);
        mDataBinding.tvGame1.setTextColor(Color.parseColor("#FFFFFF"));
        mDataBinding.ivGame2Sel.setImageResource(R.drawable.an_xz2);
        mDataBinding.tvGame2.setTextColor(Color.parseColor("#FFFFFF"));
        mDataBinding.ivGame3Sel.setImageResource(R.drawable.an_xz2);
        mDataBinding.tvGame3.setTextColor(Color.parseColor("#FFFFFF"));
    }

}